﻿using B.W.traceability.Domain.养殖;
using B.W.traceability.ErrorCode;
using B.W.traceability.Infrastructure;
using B.W.traceability.Read.API.Application.APPlicationCommand;
using MediatR;

namespace B.W.traceability.Read.API.Application.APPlicationHanlder
{
    public class TraceabilityDeleteHandler : IRequestHandler<TraceabilityDeleteCommand, APIResult<object>>
    {
        private readonly IBInfrastructure<Traceabilitytable> TraceabilitytableAPIResult;

        public TraceabilityDeleteHandler(IBInfrastructure<Traceabilitytable> traceabilitytableAPIResult)
        {
            TraceabilitytableAPIResult = traceabilitytableAPIResult;
        }

        public Task<APIResult<object>> Handle(TraceabilityDeleteCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            result.Code= ErrorAPIResult.删除成功;
            result.Msg= ErrorAPIResult.删除成功.ToString();
            var list= TraceabilitytableAPIResult.Query().Where(x=>x.Traceabilityid==request.Traceabilityid).FirstOrDefault();
            list.MyProperty = true;
            TraceabilitytableAPIResult.Uppdate(list);
            result.Data = list;
            return Task.FromResult(result);
            
        }
    }
}
